package com.hnevc.mytrafficdemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hnevc.mytrafficdemo.R;
import com.hnevc.mytrafficdemo.entity.RechargeRecord;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/12/20.
 */

public class RechargeRecordAdapter extends BaseAdapter{
    Context mContext;
    List<RechargeRecord> mRecordList;

    public RechargeRecordAdapter(Context context, List<RechargeRecord> recordList) {
        mContext = context;
        mRecordList = recordList;
    }

    @Override
    public int getCount() {
        return mRecordList.size();
    }

    @Override
    public Object getItem(int i) {
        return mRecordList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return mRecordList.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        RechargeRecord record = mRecordList.get(i);
        view = LayoutInflater.from(mContext).inflate(R.layout.record_list_item,null);

        TextView mTvDateTime = (TextView) view.findViewById(R.id.id_tv_date_time);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy.MM.dd");
        Date date = null;
        try {
            date = dateFormat.parse(record.getRechargeDate());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        mTvDateTime.setText(sdf1.format(date)+"\n"+new SimpleDateFormat("EEEE").format(date));

        return view;
    }
}
